package com.spark.core;

import java.util.HashMap;
import java.util.List;

@SuppressWarnings({ "serial", "unchecked" })
public class Message extends HashMap {
	
	private static final String SUCCESS = "success";
	
	private static final String RESULT = "result";
	
	private static final String MESSAGE = "message";
	
	private static final String CODE = "code";
	
	private static final String TITLE = "title";
	
	private static final String CONTENT = "content";
	
	private static final String FAILED_TYPE = "failedType";
	
	private static final String ERROR = "error";
	
	private static final String WARNING = "warning";
	
	private static final String SESSION_TIMEOUT = "sessionTimeout";
	
	private static final String INFO = "info";
	
	private static final String WIDTH = "width";
	
	private static final String HEIGHT = "height";
	
	public Message(boolean success){
		setSuccess(success);
	}
	
	public void setSuccess(boolean success){
		put(SUCCESS, success);
	}
	
	public void setCode(String code){
		put(CODE,code);
	}
	
	public void setContent(Object content){
		put(CONTENT,content);
	}
	
	public void setError(String msg){
		setSuccess(false);
		put(FAILED_TYPE, ERROR);
		put(MESSAGE, msg);
	}
	
	public void setWarning(String msg){
		setSuccess(false);
		put(FAILED_TYPE, WARNING);
		put(MESSAGE, msg);
	}
	
	public void setWarning(String title, String msg){
		setSuccess(false);
		put(FAILED_TYPE, WARNING);
		put(TITLE,title);
		put(MESSAGE, msg);
	}
	
	public void sessionTimeOut(){
		put(FAILED_TYPE, SESSION_TIMEOUT);
	}
	
	public void setInfo(String msg){
		setSuccess(false);
		put(FAILED_TYPE, INFO);
		put(MESSAGE, msg);
	}
	
	public void setResult(List list){
		put(RESULT, list);
	}
	
	public void setWidth(int w){
		put(WIDTH, w);
	}
	
	public void setHeiht(int h){
		put(HEIGHT, h);
	}
}
